package com.tcoiss.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tcoiss.app.domain.AdminDivision;
import com.tcoiss.app.mapper.AdminDivisionMapper;
import com.tcoiss.app.service.IAdminDivisionService;
import com.tcoiss.common.core.utils.StringUtils;
import com.tcoiss.common.datasource.annotation.DB;

import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminDivisionServiceImpl extends ServiceImpl<AdminDivisionMapper, AdminDivision> implements IAdminDivisionService {

    @Override
    public List<AdminDivision> getList(AdminDivision adminDivision) {
        LambdaQueryWrapper<AdminDivision> lqw = Wrappers.lambdaQuery();
        if(StringUtils.isNotBlank(adminDivision.getName())){
            lqw.eq(AdminDivision::getName,adminDivision.getName());
        }
        if(StringUtils.isNotBlank(adminDivision.getNumber())){
            lqw.eq(AdminDivision::getNumber,adminDivision.getNumber());
        }
        if(adminDivision.getAdministrativeLevelsId()!=null&&adminDivision.getAdministrativeLevelsId()!=0){
            lqw.eq(AdminDivision::getAdministrativeLevelsId,adminDivision.getAdministrativeLevelsId());
        }
        if(StringUtils.isNotBlank(adminDivision.getFullName())){
            if("jxs".equals(adminDivision.getFullName())){
            lqw.likeRight(AdminDivision::getFullName,"江西省");
            }else {
                lqw.eq(AdminDivision::getFullName,adminDivision.getFullName());
            }
        }
        if(adminDivision.getId()!=null&&adminDivision.getId()!=0){
            lqw.eq(AdminDivision::getId,adminDivision.getId());
        }
        lqw.eq(AdminDivision::getStatus,"C");
        if(StringUtils.isNotBlank(adminDivision.getEnable())){
            lqw.notIn(AdminDivision::getEnable,adminDivision.getEnable());
        }else {
            lqw.eq(AdminDivision::getEnable,"1");
        }
        return list(lqw);
    }


    @Override
    @DB("kingdee")
    public String getLastFullName(String lastNumber) {
        LambdaQueryWrapper<AdminDivision> lqw = Wrappers.lambdaQuery();
        if(StringUtils.isNotBlank(lastNumber)){
            lqw.eq(AdminDivision::getNumber,lastNumber);
        }
        List<AdminDivision> adminDivisions = list(lqw);
        return adminDivisions.get(0).getFullName();
    }

}
